# Пример 1
def method_logger(method):
    def wrapper(self, *args, **kwargs):
        print(f"Вызов метода {method.__name__} с аргументами: {args} и именованными аргументами: {kwargs}")
        result = method(self, *args, **kwargs)
        print(f"Метод {method.__name__} завершён с результатом: {result}")
        return result
    return wrapper

class Calculator:
    @method_logger
    def add(self, x, y):
        return x + y

    @method_logger
    def subtract(self, x, y):
        return x - y

    @method_logger
    def multiply(self, x, y):
        return x * y

    @method_logger
    def divide(self, x, y):
        if y == 0:
            raise ValueError("Деление на ноль!")
        return x / y

# Пример использования
calc = Calculator()
print(calc.add(5, 3))
print(calc.subtract(10, 4))
print(calc.multiply(3, 7))
print(calc.divide(16, 4))

# ---------------------------------------------------------------------------------------------------------------------------------------------
# Пример 2
from functools import wraps

class BotHandler:
    def __init__(self):
        self.handlers = {}

    def command(self, command):
        def decorator(func):
            @wraps(func)
            def wrapper(*args, **kwargs):
                return func(*args, **kwargs)
            self.handlers[command] = wrapper
            return wrapper
        return decorator

    def handle_command(self, command, *args, **kwargs):
        handler = self.handlers.get(command)
        if handler:
            return handler(*args, **kwargs)
        else:
            print(f"No handler found for command: {command}")

# Пример использования
bot = BotHandler()

@bot.command("start")
def start_handler():
    return "Starting bot!"

@bot.command("help")
def help_handler():
    return "Here is some help."

# Обработка команд
print(bot.handle_command("start"))  # Выведет: Starting bot!
print(bot.handle_command("help"))   # Выведет: Here is some help.
print(bot.handle_command("unknown"))  # Выведет: No handler found for command: unknown

# ---------------------------------------------------------------------------------------------------------------------------------------------